package com.ashlikun.okhttputils.simple.retrofit

import androidx.annotation.Keep
import com.ashlikun.okhttputils.http.request.HttpRequest
import com.ashlikun.okhttputils.http.response.HttpResponse
import com.ashlikun.okhttputils.http.response.HttpResult
import com.ashlikun.okhttputils.retrofit.*
import com.ashlikun.okhttputils.simple.ParseMulti
import com.ashlikun.okhttputils.simple.data.Adwwww
import com.ashlikun.okhttputils.simple.data.HttpPageResultX
import com.ashlikun.okhttputils.simple.data.UserData
import com.ashlikun.okhttputils.simple.data.WeiJinModel
import okhttp3.Response
import java.io.File
import kotlin.math.min


/**
 * 作者　　: 李坤
 * 创建时间: 2017/8/10　9:31
 * 邮箱　　：496546144@qq.com
 *
 *
 * 功能介绍：请求mode类
 */
fun String.requestGet(): HttpRequest = HttpRequest.get(this)
fun String.requestPost(): HttpRequest = HttpRequest.post(this)

@Keep
interface ApiOther : BaseApi {
    companion object {
        val api: ApiOther by lazy {
            Retrofit.get().create(ApiOther::class.java)
        }
    }

    fun testx(
        handle: Int
    ): String? {
        return "11111111111"
    }

    @Get("https://api-sip.510gow.com/interface?action=recommend")
    @ParseMulti
    suspend fun test(
        news_id: Int,
        ddd: WeiJinModel
    ): HttpResult<List<UserData>>

    @Json()
    @Post("https://api-sip.510gow.com/interface?action=recommend")
    @ParseMulti
    suspend fun testList(
        news_id: Int,
        ddd: List<Adwwww>
    ): HttpResponse

    suspend fun test2(
        @Field(key = "news_id")
        tikit: Int,
    ): HttpResponse

    @Action("action:recommend")
    suspend fun test3(
        @Field(key = "news_id")
        tikit: Int,
    ): HttpResponse

    @Action("recommend")
    suspend fun test4(
        @Field(key = "news_id")
        tikit: Int,
    ): HttpResponse

    @Action("action:")
    @Path("/interface?")
    suspend fun test5(
        @Field(key = "news_id")
        tikit: Int,
    ): HttpResponse

    @Path("/interface?", replace = true)
    suspend fun test6(): HttpResponse

    @Path("/{id}/user/me/{sid}?")
    @Params("Cookie:session=abc123; user=john", isHeader = true)
    @Params("session:abc", isHeader = true)
    @Params("a:1/中文123", "b:2", isUrlQuery = true)
    @Params("c:3", "d:4", isUrlQuery = false)
    suspend fun test7(
        @Field(key = "id", isPath = true)
        id: Int,
        @Field(key = "sid", isPath = true)
        sid: String,
        @Field(isUrlQuery = true)
        version: String,
    ): HttpResponse

    //    @Path("/{id}/user/me/{sid}?")
    @Params("Cookie:session=abc123; user=john", isHeader = true)
    @Params("session:abc", isHeader = true)
    @Params("a:1/中文123", "b:2", isUrlQuery = true)
    @Params("c:3", "d:4", isUrlQuery = false)
    suspend fun testFile(
        file: File,
        @Field(key = "id", isPath = true)
        id: Int,
        @Field(key = "sid", isPath = true)
        sid: String,
        @Field(isUrlQuery = true)
        version: Int = min(111, RetrofitTest.getAddd()),
    ): HttpResponse

    /**
     * 上传文件
     */
    @Params("api:SYNO.FileStation.Upload", isUrlQuery = true)
    @Params("method:upload", isUrlQuery = true)
    @Params("create_parents:true", isUrlQuery = false)
    @Params(
        key = "Cookie",
        text = ":did=cBRo-xgVn_Xu8qopOs4OKWMQhYZheDBZ0p6RVIwjlMWUDPjKsQI0_vRrUooErEktv1nRKQXv26x5OBWXEb-P1A;id=oau3uQf1wLV3PPzof4UWrdbms8WJyu2BlYRWHtxuNhoh_WZ_yA1cqwkpzVVGK0hqouyEmYO13D2JC85-iWkjkA",
        isHeader = true
    )
    @ConfigMultipartFormDataNoContentLength()
    suspend fun fileUpload(
        @Field(isFile = true)
        file: File,
        path: String,
        mtime: Long,
        size: Long,
        overwrite: Boolean = true,
        @Field(isUrlQuery = true)
        version: Int = 2,
    ): HttpResponse

    /**
     * api=SYNO.FileStation.Download&version=1&method=download&path=${Uri.encodeComponent(file['path'])}&mode=open&_sid=${Util.sid}
     */
    @Get
    @Params("api:SYNO.FileStation.Download")
    @Params("method:download")
    @Params("version:1")
    @Params("mode:open")
    suspend fun downloadFile(path: String, _sid: String = "9RF583RjczrkMbXtjbxjzDkM7YdLws9JXlnrbHSmMhsGTEr5OClBeTAKTOkFwNHynxSh3-Ixq1EEGIY0n-_fi8"): ByteArray
}
